{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "### Pull Performance Report Results with GS Quant\n",
    "\n",
    "First authenticate your session and then get your portfolio's performance report:"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "import datetime as dt\n",
    "import pandas as pd\n",
    "import warnings\n",
    "\n",
    "from IPython.display import display\n",
    "\n",
    "from gs_quant.markets.portfolio_manager import PortfolioManager\n",
    "from gs_quant.markets.securities import Asset, AssetIdentifier\n",
    "from gs_quant.session import GsSession, Environment\n",
    "\n",
    "GsSession.use(Environment.PROD)\n",
    "warnings.filterwarnings(\"ignore\", category=RuntimeWarning)\n",
    "\n",
    "pm = PortfolioManager('MPWQQ8B05FKPCCH6')\n",
    "performance_report = pm.get_performance_report()\n",
    "start_date = performance_report.earliest_start_date\n",
    "end_date = performance_report.latest_end_date"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "Now that we have our performance report, we can leverage the unique functionalities of the PerformanceReport class to pull daily exposure and PnL data:"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "all_exposures = performance_report.get_many_measures(\n",
    "    start_date=start_date,\n",
    "    end_date=end_date,\n",
    "    measures=['pnl', 'grossExposure', 'netExposure']\n",
    ")\n",
    "\n",
    "print(all_exposures)\n",
    "all_exposures.plot(title='Performance Breakdown')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "Now let's pull Brinson Attribution data to analyze the PnL of your portfolio compared to a benchmark, which can be any equity ETF, Index, or Basket in Marquee:"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "asset = Asset.get(id_value='MXWO', id_type=AssetIdentifier.TICKER)\n",
    "\n",
    "brinson_attribution_results = performance_report.get_brinson_attribution(\n",
    "    benchmark=asset.get_marquee_id(),\n",
    "    include_interaction=True,\n",
    "    start_date=start_date,\n",
    "    end_date=end_date\n",
    ")\n",
    "\n",
    "display(pd.DataFrame(brinson_attribution_results))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
